﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace Frame
{
    public class ErrorMessage
    {
        FrameApplication m_app;
        private string FilePath = System.Windows.Forms.Application.StartupPath + @"\PARAM\ErrInfo.xml";
        private XmlDocument xmlDoc;
        private Dictionary<int, string> errDic;
        public ErrorMessage(FrameApplication app)
        {
            this.m_app = app;
            errDic = new Dictionary<int, string>();
            LoadFIle();
            
        }

        private bool LoadFIle()
        {
            if (xmlDoc == null)
                xmlDoc = new XmlDocument();
            if (!File.Exists(FilePath)) return false;
            xmlDoc.Load(FilePath);
            XmlNodeList errNodes = xmlDoc.SelectSingleNode("ErrorMessage").ChildNodes;
            errDic.Clear();
            foreach (XmlNode errNode in errNodes)
            {
                int key = Convert.ToInt32(errNode.Attributes["id"].Value.ToString());
                string value = errNode.InnerText;
                errDic.Add(key, value);
            }
            return true;
        }

        public string GetErrInfo(int err_id)
        {
            string value = string.Empty;
            errDic.TryGetValue(err_id, out value);
            return value;
        }
        
    }
}
